package com.ibm.sample.library.web.action;

import java.util.List;

import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import com.ibm.sample.library.model.Category;
import com.ibm.sample.library.service.IService;
import com.opensymphony.xwork2.ActionSupport;

@ParentPackage("json-default")
@Result(name = "success", type = "json", params = { "root", "categories" })
public class FindCategoryAction extends ActionSupport
{
    private static final long serialVersionUID = 1L;

    @Autowired
    private IService service;

    private Category[] categories;

    @Override
    public String execute() throws Exception
    {
        List<Category> categoryList = service.findAllCategory();
        categories = categoryList.toArray(new Category[categoryList.size()]);

        return SUCCESS;
    }

    public Category[] getCategories()
    {
        return categories;
    }

    public void setCategories(Category[] categories)
    {
        this.categories = categories;
    }
}
